import logging

import pytest
import yaml
from selenium import webdriver


@pytest.fixture(scope='session')
def chrome_driver():
    logging.info("初始化 Chrome driver")
    driver = webdriver.Chrome()
    driver.implicitly_wait(5)
    yield driver
    logging.info("退出 Chrome driver")
    driver.quit()

@pytest.fixture(scope='class')
def debug_driver():
    logging.info("这是实例化一个debug模式的driver")
    opt = webdriver.ChromeOptions()
    opt.debugger_address = "127.0.0.1:9222"
    driver = webdriver.Chrome(options=opt)
    yield driver
    logging.info("利用完毕！")
    driver.quit()   # 其实debug模式下quit不quit没所谓。


@pytest.fixture(scope='class')
def read_cookies():
    """
    从本地cookies文件中读取
    :return:
    """
    with open("../cookies/cookies.yaml", "r", encoding='utf-8') as f:
        local_cookies = yaml.safe_load(f)
    return local_cookies